package com.wyt.cloud.utils.designpatterns.dutychain;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class HandlerContext<T> {

    /**
     * 双向链表
     */
    //指向前一个节点的指针
    public HandlerContext<T> preContext;
    //指向下一个节点的指针
    public HandlerContext<T> nextContext;

    @Getter
    @Setter
    private IHandler<T> handler;


    public void next(T targetBiz) {
        if(nextContext==null){
            return;
        }
        handler.execute(targetBiz);
        nextContext.next(targetBiz);
    }
}
